<?php

include_once "../main.php";
include_once "../conn.php";

$stt   = $_GET['s'];
$uname = $_GET['uname'];
$ename = $_GET['ename'];

// 
// Start retrive data from database
//
$q2 = "SELECT * FROM job_employer_info WHERE ename = '$ename'";
$r2 = mysql_query($q2) or die(mysql_error());
$a2 = mysql_fetch_array($r2);

$q3 = "SELECT * FROM job_seeker_info WHERE uname = '$uname'";
$r3 = mysql_query($q3) or die(mysql_error());
$a3 = mysql_fetch_array($r3);

$q4 = "SELECT * FROM job_view WHERE uname = '$uname' AND ename = '$ename' ";
$r4 = mysql_query($q4) or die(mysql_error());
$a4 = mysql_fetch_array($r4);

//
// Check if status is set to yes, jobseeker cannot reject to view resume again
//
if($a4['status'] == 'n' || $a4['status'] == 'p'){

$q1 = "UPDATE `job_view` SET `status` = '$stt' WHERE ename = '$ename' AND uname = '$uname' "; 
$r1 = mysql_query($q1) or die(mysql_error());

//
// Check if jobseeker has aproved to view resume
//
if ($stt == 'y'){
		echo "<br><br>";
		echo "Your approval to view your resume has been sent to $a2[CompanyName]<br>";
		echo "By the way, please update your latest resume if you have not done it yet.<br><br>Thank you.";

//
// Create subject and message body to send email
//
$sub   = "Approved to view resume by $a3[fname] $a3[lname].";
$msg   = "Hi $a2[CompanyName],

$a3[fname] $a3[lname] has approved you to view his/her resume.

All the best and thank you.

From $sitename
";

//
// Start send email
//		
		$headers = "MIME-Version: 1.0\n"; 
		$headers .= "Content-type: text/plain; charset=iso-8859-1\n";
		$headers .= "Content-Transfer-Encoding: 8bit\n"; 
		$headers .= "From: $_SERVER[HTTP_HOST] <$aset[ContactEmail]>\n"; 
		$headers .= "X-Priority: 1\n"; 
		$headers .= "X-MSMail-Priority: High\n"; 
		$headers .= "X-Mailer: PHP/" . phpversion()."\n";
		
		$to = $a2['CompanyEmail'];
		$subject = $sub;
		$message_body = $msg; 
		$b = @mail($to, $subject, $message_body, $headers);
}

else{
		echo "<br><br>";
		echo "Your rejected to view your resume has been sent to $a2[CompanyName].<br>";
		echo "Thank you for your reply.";

//
// Create subject and message body to send email
//		
$sub   = "Rejected to view resume by $a3[fname] $a3[lname].";
$msg   = "Hi $a2[CompanyName],

Sorry to tell you that $a3[fname] $a3[lname] has rejected you to view his/her resume.

All the best and thank you.

From $sitename
";

//
// Start send email
//	
		$headers = "MIME-Version: 1.0\n"; 
		$headers .= "Content-type: text/plain; charset=iso-8859-1\n";
		$headers .= "Content-Transfer-Encoding: 8bit\n"; 
		$headers .= "From: $_SERVER[HTTP_HOST] <$aset[ContactEmail]>\n"; 
		$headers .= "X-Priority: 1\n"; 
		$headers .= "X-MSMail-Priority: High\n"; 
		$headers .= "X-Mailer: PHP/" . phpversion()."\n";
		
		$to = $a2['CompanyEmail'];
		$subject = $sub;
		$message_body = $msg; 
		$b = @mail($to, $subject, $message_body, $headers);
		
	}
}

else {
echo "Sorry, you can't rejected $a2[CompanyName] to view your resume since you have approved it before.<br>Thank you.";
$q1 = "UPDATE `job_view` SET `status` = 'y' WHERE ename = '$ename' AND uname = '$uname' "; 
$r1 = mysql_query($q1) or die(mysql_error());
}

?>